package likouJava;

public class 搜索二维矩阵 {
    public boolean searchMatrix(int[][] matrix, int target) {
        int m = matrix.length;
        int n = matrix[0].length;

        int left = 0,right = m * n - 1;

        while (left <= right){
            int mid = left + (right - left) / 2;
            int midVal = matrix[mid / n][mid % n];

            if (midVal == target){
                return true;
            } else if (midVal > target) {
                right = mid - 1;
            }else{
                left = mid + 1;
            }
        }
        return false;
    }

}
